/*
* Copyright 2010 Competentum group
*
* Licensed under the GNU General Public License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.gnu.org/licenses/gpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.competentum.builders
{
	import com.competentum.vos.AbstractItemVO;
	import com.competentum.vos.BindVO;
	import com.competentum.vos.ProjectVO;
	import com.competentum.windows.Scope;
	import com.competentum.lib.data.builders.AbstractDataBuilder;
	import com.competentum.lib.data.vo.UniqueVO;
	
	import mx.collections.IList;

	/**
	 * This Builder holds all Projects and provides us with methods to create and handle them 
	 * 
	 * @author Osipov Sergey
	 * 
	 */	
	public class ProjectsBuilder extends AbstractDataBuilder
	{
		public static const TYPE:String = "ProjectsBuilder";

		private var scope:Scope;

		override public function get global():Boolean
		{
			return false;
		}

		public function ProjectsBuilder(scope:Scope)
		{
			super(TYPE, 'project');
			this.scope = scope;
		}
		
		/**
		 * 
		 * @param xml
		 * @return 
		 * 
		 */		
		public function createItemFromXML(xml:XML, addToArray:Boolean = true):AbstractItemVO
		{
			return createItem(xml.@name, xml.@groupingAttribute, xml.@duration, xml.@comments, xml.@uid, addToArray);
		}
		
		public function createItem(name:String, groupingAttribute:String, hours:Number, comments:String = null, uid:String = null, addToArray:Boolean = true):ProjectVO
		{
			var item:ProjectVO = new ProjectVO();
			item.name = name;
			item.groupingAttribute = groupingAttribute;
			item.hours = hours;
			item.comments = comments;
			item.uid = uid;
			item.scope = scope;
			validateUID(item);
			if (addToArray)
				addItem(item);
			
			return item;
		}
	}
}